package com.cloud.lan.api;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.cloud.lan.api.dto.req.WxGenerateschemeRequest;
import com.cloud.lan.api.dto.resp.WxGenerateschemeResponse;
import com.cloud.lan.entity.base.BaseResponse;
import com.cloud.lan.entity.constant.WxDataConstant;
import com.cloud.lan.service.tx.wx.config.WxMaConfiguration;

import com.cloud.lan.service.tx.wx.config.WxMpConfiguration;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

/**
 * 测试
 * @author ErKang
 * @date Created in 2021/12/5 04:24
 * @title TestApi.java
 * Department: Product development
 */

@Slf4j
@RestController
@RequestMapping(value = {"/v1/wx/api/"}, method = {RequestMethod.GET, RequestMethod.POST}, consumes = {"*/*"}, produces = {"application/json"})
public class WxApi {

    @Resource
    WxMaConfiguration wxMaConfiguration;

    @RequestMapping("refreshAccessToken")
    public BaseResponse<Object> refreshAccessToken(String pwd) {
        String accessToken = null;
        try {
            if ("ek".equals(pwd)) {
                log.info("#手动刷新 refreshAccessToken");
                String wxTK = wxMaConfiguration.reFreshWXTk(WxDataConstant.APPID);
                log.info("#手动刷新完成 {} ", wxTK);
            }
        } catch (Exception e) {
            log.error(" 手动刷新完成 refreshAccessToken 失败", e);
        }
        return BaseResponse.success(accessToken);
    }


    @RequestMapping("generatescheme")
    public BaseResponse<WxGenerateschemeResponse> generatescheme(WxGenerateschemeRequest request) {
        return wxMaConfiguration.generatescheme(request);
    }

}
